/*
    Author: Christopher Diggins
    License: MIT Licence 1.0
    Website: http://www.cdiggins.com
*/

namespace cvm
{
	void Test1() {
		Any x = 6;
		Any y = x.ToInt() + 1;
		Any z = x;
		gInt.Mul(z, y);
		printf("%d * %d = %d, expected 6 * 7 = 42\n", x.ToInt(), y.ToInt(), z.ToInt());
	}

	void Test2() {
		AnyStack s;
		Any a; Any b;
		s.Push(1);
		s.Push(2);
		s.Swap();
		s.Pull(a);
		s.Pull(b);
		printf("Expect 1, 2: %d, %d\n", a.ToInt(), b.ToInt());
		assert(s.IsEmpty());
		for (int i=0; i < BUFF_SIZE; ++i) {
			s.Push(i);
		}
		assert(s.IsFull());
		assert(s.Top().ToInt() == BUFF_SIZE - 1);
	}

	void PrintStack(AnyStack& s) {
		while (!s.IsEmpty()) {
			ScopedAny a;
			s.Pull(a.any);
			a.any.Write();
			printf(" ");
		}
	}

	void StackTest(AnyStack& a, PChar expected) {
		printf("expected: %s\nresult:   ", expected);
		PrintStack(a);
		printf("\n");
	}

	void Test3() {
		{
			AnyStack xs; xs.Push(1); xs.Push(2); xs.Push(3);
			StackTest(xs, "3 2 1");
		}
		{ 
			AnyStack xs; xs.Push(1); xs.Push(true); xs.Push('q'); xs.SwapNM(1,2); 
			StackTest(xs, "q 1 true");
		}
		{
			AnyStack xs; xs.Push(1); xs.Push(2); xs.Dup();
			StackTest(xs, "2 2 1");
		}
		{
			AnyStack xs; xs.Push(1); xs.Push(2); xs.Pop();
			StackTest(xs, "1");
		}
		{
			AnyStack xs; xs.Push(1); xs.Push(2); xs.Push(3); xs.GetN(1);
			StackTest(xs, "2 3 2 1");
		}
		{
			AnyStack xs; xs.Push(1); xs.Push(2); xs.Push(3); xs.SetN(1);
			StackTest(xs, "2 3");
		}
	}

	void RunTests() {
		Test1();
		Test2();
		Test3();
	}
}
